#include "localMovieListMessage.h"
#include <rapidjson/document.h>
#include "jsonUtils.h"

LocalMovieListMessage::LocalMovieListMessage(MtpProtocol* packet) : MtpMessage(packet),page(1),limit(10)
{

}

LocalMovieListMessage::LocalMovieListMessage(int page, int limit) : MtpMessage(new MtpProtocol(L"localMovieList")), page(page), limit(limit)
{

}

void LocalMovieListMessage::decodeBody()
{
	MtpMessage::decodeBody();
	if (!jsonContent.empty()) {
		JsonDoc doc;
		doc.Parse(jsonContent.c_str());
		JsonUtils::loadInt(doc, L"page", page);
		JsonUtils::loadInt(doc, L"limit", limit);
		JsonUtils::loadStr(doc, L"name", name);
	}
}

void LocalMovieListMessage::encodeBody()
{
	JsonDoc doc;
	doc.SetObject();
	doc.AddMember(L"page", page, doc.GetAllocator());
	doc.AddMember(L"limit", limit, doc.GetAllocator());
	JsonUtils::addString(doc, L"name", name, doc.GetAllocator());
	jsonContent = JsonUtils::jsonStr(doc);
	MtpMessage::encodeBody();
}

const int& LocalMovieListMessage::getPage() const
{
	return page;
}

const int& LocalMovieListMessage::getLimit() const
{
	return limit;
}

const String& LocalMovieListMessage::getName() const
{
	return name;
}
